package com.eztalks.selenium;

import java.io.File;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;

public class UcTest {
	@Test
	public void fun1() {
		try {
			// 谷歌
			System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
					"C:\\Users\\liurong\\Downloads\\chromedriver.exe");
			WebDriver driver = new ChromeDriver();

			// 火狐
			// System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY,
			// "C:\\Users\\liurong\\Downloads\\geckodriver.exe");
			// WebDriver driver = new FirefoxDriver();

			driver.manage().window().maximize();
			driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);

			driver.get("https://uctest.eztalks.com:8888");

			File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
			System.out.println(screenshot);

			FileUtils.copyFile(screenshot, new File("D:\\screenshotsscreenshots1.jpg"));

			// 登录uc
			this.login(driver);

			screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

			FileUtils.copyFile(screenshot, new File("D:\\screenshotsscreenshots2.jpg"));

			// 预约会议
			this.createMeeting(driver);

			screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

			FileUtils.copyFile(screenshot, new File("D:\\screenshotsscreenshots3.jpg"));
			// 邀请
			this.invite(driver);

			screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

			FileUtils.copyFile(screenshot, new File("D:\\screenshotsscreenshots4.jpg"));
			// driver.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 登录
	 * 
	 * @param driver
	 */
	private void login(WebDriver driver) {
		driver.findElement(By.xpath("//input[@id='email']")).sendKeys("liurong@fsmeeting.com");
		driver.findElement(By.xpath("//input[@id='password']")).sendKeys("123456");
		driver.findElement(By
				.xpath("//button[@class='ant-btn UcButton_button_TwRYB UcButton_primary_3k6kq SharedStyle_button_BQ8Hz ant-btn-lg']"))
				.click();
	}

	/**
	 * 预约会议
	 * 
	 * @param driver
	 */
	private void createMeeting(WebDriver driver) {
		driver.findElement(
				By.xpath("//div[@class='LeftNavItem_item_11F_Q LeftNavItem_unchose_3JClD LeftNav_nav-item_17he2']"))
				.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//ul[@class='tab_link-ul_2NGue']/li[3]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(
				By.xpath("//button[@class='ant-btn UcButton_button_TwRYB UcButton_primary_3k6kq ant-btn-lg']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	}

	/**
	 * 会议邀请
	 * 
	 * @param driver
	 */
	private void invite(WebDriver driver) {
		driver.findElement(By.xpath("//tbody[@class='ant-table-tbody']/tr[1]/td[5]/div/span[2]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//div[@class='ant-tabs-nav ant-tabs-nav-animated']/div[3]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//div[@class='UpcomingMeetingView_editor_W_slC']")).sendKeys("ddddd2@fff.com");
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By
				.xpath("//div[@class='ant-tabs-tabpane ant-tabs-tabpane-active']/button[@class='ant-btn UcButton_button_TwRYB UcButton_primary_3k6kq']"))
				.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	}
}
